//index.js
//获取应用实例
var api = require("../../api.js"),page_first_init = !0
const app = getApp()

Page({
    data: {
      showThis: false,
    text: '',
    showIcon: false,
    isLoading: false,
        showPopup:false,
        motto: 'Hello World',
        userInfo: {},
        hasUserInfo: false,
        is_tabs:true,
        data_tip:[],
        canIUse: wx.canIUse('button.open-type.getUserInfo'),
        currentTab: 0,
        navScrollLeft: 0,
        dots:[],
        currentSwiper: 0,
        autoplay: true,
        height:20,
        dataInfo:{},
        id:null,
        page_index:1,
        title_image:'',
        position:false,
        act_modal_list:[
          {
            active_color: "#ff4544",
            active_icon: "http://ys.macoolliving.com/web/statics/images/appnavbar/nav-icon-index.active.png",
            color: "#888",
            icon: "http://ys.macoolliving.com/web/statics/images/appnavbar/nav-icon-index.png",
            new_url: "/pages/edit_index/edit_index",
            text: "商城",
            index:0
          },
            {
                active_color: "#ff4544",
                active_icon: 'https://ysc.macoolliving.com/uploads/image/store_1/5fbf9630ab800.png',
                color: "#888",
                icon: 'https://ysc.macoolliving.com/uploads/image/store_1/5fbf9358eb189.png',
                new_url: "/pages/vip/vip",
                text: "关于马库",
                url: "/pages/vip/vip",
                index:1
            },
          // {
          //   active_color: "#ff4544",
          //   active_icon: "http://ys.mingsxx.com/web/statics/images/appnavbar/nav-icon-cat.active.png",
          //   color: "#888",
          //   icon: "http://ys.mingsxx.com/web/statics/images/appnavbar/nav-icon-cat.png",
          //   new_url: "/pages/cat/cat",
          //   text: "分类",
          //   url: "/pages/cat/cat",
          //   index:1
          // },
          {
            active_color: "#ff4544",
            active_icon: "http://ys.mingsxx.com/web/statics/images/appnavbar/nav-icon-cart.active.png",
            color: "#888",
            icon: "http://ys.mingsxx.com/web/statics/images/appnavbar/nav-icon-cart.png",
            new_url: "/pages/cart/cart",
            text: "购物车",
            url: "/pages/cart/cart",
            index:2
          },
          {
            active_color: "#ff4544",
            active_icon: "http://ys.mingsxx.com/web/statics/images/appnavbar/nav-icon-user.active.png",
            color: "#888",
            icon: "http://ys.mingsxx.com/web/statics/images/appnavbar/nav-icon-user.png",
            new_url: "/pages/user/user",
            text: "我",
            url: "/pages/user/user",
            index:3
          }
        ]
    },
    onPageScroll:function(e){
        this.setData({
            position:e.scrollTop>=100?true:false
        })
    },
    closePopup(){
        this.setData({
            showPopup:false
        })
    },
    sanCode(){
        wx.scanCode({
            onlyFromCamera:false,
            scanType:['qrCode','barCode'],
            success(res) {
                console.log(res)
            }
        })
    },
    //事件处理函数
    onLoad: function (t) {
      let _self = this;
        app.loginBindParent({
            parent_id: t.scene
        });
      app.request({
        url: api.default.index,
        data: {},
        method: "POST",
        success: function(t) {
            let showPopup = this.data.showPopup;
          for(let i=0;i<t.data.module_list_2.length;i++){
              if(t.data.module_list_2[i].content.enable == 1) showPopup = true
              if(t.data.module_list_2[i].module_name == 'title') wx.setNavigationBarTitle({title: t.data.module_list_2[i].content.name})
          }
          _self.setData({
            look:'123',
            dataInfo:t.data.module_list_2,
              showPopup
          })
        }
      })
      this.setContainerHeight()
    },
    onShareAppMessage: function(t) {
      var a = this;
      return {
          path: "/pages/edit_index/edit_index?user_id=" + wx.getStorageSync("user_info").id,
          success: function(t) {
              1 == ++share_count && app.shareSendCoupon(a);
          },
          title: a.data.store.name
      };
    },
    loadData: function(t) {
      var o = this, a = wx.getStorageSync("pages_edit_index_edit_index");
      a && (a.act_modal_list = [], o.setData(a)), app.request({
          url: api.default.index,
          success: function(t) {
              if (0 == t.code) {
                  page_first_init ? page_first_init = !1 : t.data.act_modal_list = [];
                  var a = t.data.topic_list, e = new Array();
                  if (a && 1 != t.data.update_list.topic.count) {
                      if (1 == a.length) e[0] = new Array(), e[0] = a; else for (var i = 0, r = 0; i < a.length; i += 2,
                      r++) null != a[i + 1] && (e[r] = new Array(), e[r][0] = a[i], e[r][1] = a[i + 1]);
                      t.data.topic_list = e;
                  }
                  o.setData(t.data), wx.setStorageSync("store", t.data.store), wx.setStorageSync("pages_edit_index_edit_index", t.data);
                  var s = wx.getStorageSync("user_info");
                  s && o.setData({
                      _user_info: s
                  })
              }
          },
          complete: function() {
              wx.stopPullDownRefresh();
          }
      });
  },
    setContainerHeight:function(e){
      var sysInfo = wx.getSystemInfoSync();//同步获取设备宽度
      var screenWidth = sysInfo.screenWidth; //获取屏幕的宽度
      var scale=(screenWidth * 2.5) / 2;
      this.setData({
        height: scale
      })
    },
    swiperChange: function (e) {
      this.setData({
        currentSwiper: e.detail.current
      })
    },
    scrollToLower(e){
      let all_Arr = this.data_tip;
      const _self = this;
      app.request({
        url:api.default.goods_list,
        data:{cat_id:id,page:_self.data.page_index},
        success:function(t){
          for(let i=0;i<t.data.list.length;i++){
            all_Arr.push(t.data.list[i])
          }
          _self.setData({
            data_tip:all_Arr
          })
        }
      })
    },
    switchNav(event){
      const _self = this
        var cur = event.currentTarget.dataset.current;
        var id = event.currentTarget.dataset.id;
        var title_image = event.currentTarget.dataset.img
        if(id){
          this.setData({
            is_tabs:false,
            id:id,
            page_index:1,
            title_image:title_image
          }),
          app.request({
            url:api.default.goods_list,
            data:{cat_id:id,page:_self.data.page_index},
            success:function(t){
              _self.setData({
                data_tip:t.data.list,
                page_index:t.data.page_count + 1
              })
            }
          })
        }else{
          this.setData({
            is_tabs:true,
            id:null
          })
        }
        if (this.data.currentTab == cur) {
            return false;
        } else {
            this.setData({
                currentTab: cur
            })
        }
    },
  tagsClick(e){
    let item = e.currentTarget.dataset.item
    wx.navigateTo({
      url:'/pages/tags_list/tags_list?id='+item.id
    })
  },
    importImage(e){
        wx.navigateTo({
            url:'/pages/showImg/showImg?url='+ e.currentTarget.id+'&name='+e.currentTarget.dataset.name
        })
    },
    importClick(e){
        wx.navigateTo({
            url:'/pages/list/list?cat_id='+ e.currentTarget.id
        })
    }
})
